<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('补考信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>开启时间：</label>
                            <input type="text" class="time-input" placeholder="请选择开启时间" name="startTime"/>
                        </li>
                        <li>
                            <label>结束时间：</label>
                            <input type="text" class="time-input" placeholder="请选择结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="cws:homework:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="cws:resit:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cws:resit:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('cws:resit:edit')}]];
    var submitFlag = [[${@permission.hasPermi('cws:resit:submit')}]];
    var sendFlag = [[${@permission.hasPermi('cws:resit:email')}]];
    var prefix = ctx + "cws/resit";
    var resitScorePrefix = ctx + "cws/resitscore";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "补考信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'resitId',
                    title: '补考id',
                    visible: false
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'courseYear',
                    title: '年份'
                },
                {
                    field: 'isUp',
                    title: '学期'
                },
                // {
                //     field: 'score',
                //     title: '原成绩得分'
                // },
                {
                    field: 'bkScore',
                    title: '补考得分',
                    formatter: function (value, row, index) {
                        if (value == null) {
                            return '<span style="color: red">' + '未批改' + '</span>';
                        } else if(value < 60){
                            return '<span style="color: red">' + value + '</span>';
                        }else {
                            return '<span style="color: green">' + value + '</span>';
                        }
                    }
                },
                {
                    field: 'startTime',
                    title: '开启时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    field: 'isEnd',
                    title: '状态',
                    formatter: function (value, row, index) {
                        if (value == '进行中') {
                            return '<span style="color: green">' + value + '</span>';
                        } else if(value == '未开始'){
                            return '<span style="color: #a47e3c">' + value + '</span>';
                        } else{
                            return '<span style="color: red">' + value + '</span>';
                        }
                    }
                },
                {
                    field: 'isSubmit',
                    title: '是否提交',
                    formatter: function (value, row, index) {
                        if (value == '已提交') {
                            return '<span style="color: green">' + value + '</span>';
                        } else {
                            return '<span style="color: red">' + '未提交' + '</span>';
                        }
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-warning btn-xs ' + sendFlag + '" href="javascript:void(0)" onclick="sendEmail(\'' + row.resitId + '\')"><i class="fa fa-send"></i>邮箱</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + submitFlag + '" href="javascript:void(0)" onclick="submitDoc(\'' + row.resitId + '\' , \'' + row.courseName + '\')"><i class="fa fa-edit"></i>提交</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function sendEmail(resitId) {
        setTimeout(function () {
            $.modal.alertSuccess("发送成功！");
        }, 1500);
    }

    function submitDoc(resitId,courseName) {
        $.modal.open(courseName + "补考提交",resitScorePrefix + "/add/" + resitId);
    }
</script>
</body>
</html>